package structure;

import java.util.ArrayList;

import algorithm.miscellaneous;

public class bigProductionWithLookahead {

	private ArrayList<String> rightside;
	private String leftside;
	private ArrayList<String[]> connection;
	private ArrayList<String> lookahead;
	
	public bigProductionWithLookahead(String leftside,
									  ArrayList<String> rightside,
									  ArrayList<String[]> connection,
									  ArrayList<String> lookahead){
		this.leftside= leftside;
		this.rightside= rightside;
		this.connection= connection;
		
		if(lookahead == null)
			this.lookahead= new ArrayList<String>();
		else 
			this.lookahead= lookahead;
	}
	
	public ArrayList<String> getLookahead(){
		
		return this.lookahead;
	}
	
	public String getLeftside(){
		
		return this.leftside;
	}
	
	public ArrayList<String> getRightside(){
		
		return this.rightside;
	}
	
	public ArrayList<String[]> getConnection(){
		
		return this.connection;
	}
	
	public void setLookahead(ArrayList<String> lookahead){
		
		this.lookahead.clear();
		miscellaneous.addAllOnce(lookahead, this.lookahead);
	}
	
	public boolean sameLookahead(ArrayList<String> lookahead){
		
		boolean toReturn= true;
		
		if(this.lookahead.size() != lookahead.size()) 
			toReturn= false;
		
		for(int i=0; i<this.lookahead.size(); i++){

			boolean same= false;
			for(int j=0; j<lookahead.size(); j++){
				
				if(this.lookahead.get(i).equals(lookahead.get(j))){
					
					same= true;
				}
			}
			
			if(!same){
				
				toReturn= false;
				break;
			}
		}
		
		
		return toReturn;
	}
	
	public boolean sameRightside(ArrayList<String> rightside){
		
		boolean toReturn= true;
		
		if(this.rightside.size() != rightside.size()) 
			toReturn= false;
		
		for(int i=0; i<this.rightside.size(); i++){

			boolean same= false;
			for(int j=0; j<rightside.size(); j++){
				
				if(this.rightside.get(i).equals(rightside.get(j))){
					
					same= true;
				}
			}
			
			if(!same){
				
				toReturn= false;
				break;
			}
		}
		
		
		return toReturn;
	}
	
	public void printItAll(){
		
		if(this.connection.size() > 1){
			for(String[] as : this.connection){
				
				System.out.print("(" + this.leftside + "->" + as[0] +" "+ ", " + this.lookahead + ") --->" + as[1] + " ");
			}
			
			String g= this.connection.get(this.connection.size()-1)[2];
			System.out.println("(" + this.leftside + "->" + g + " "+ ", " + this.lookahead + ") ");
		}
		else if(this.connection.size() == 1){
			
			System.out.println("(" + this.leftside + "->" + this.connection.get(0)[0] +")");
		}
	}
}
